<?php

/**
 * This is the model class for table "cart_product_map".
 *
 * The followings are the available columns in table 'cart_product_map':
 * @property integer $id
 * @property string $productid
 * @property string $customerid
 * @property string $cartid
 * @property integer $num
 * @property double $amount
 * @property double $total
 *
 * The followings are the available model relations:
 * @property Cart $cart
 * @property Product $product
 */
class CartProductMap extends CommonActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return CartProductMap the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'cart_product_map';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('num', 'numerical', 'integerOnly'=>true),
			array('amount, total', 'numerical'),
			array('productid, customerid, cartid', 'length', 'max'=>11),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, productid, customerid, cartid, num, amount, total', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'cart' => array(self::BELONGS_TO, 'Cart', 'cartid'),
			'product' => array(self::BELONGS_TO, 'Product', 'productid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '商品编号',
			'productid' => 'Productid',
			'customerid' => 'Customerid',
			'cartid' => 'Cartid',
			'num' => '商品数',
			'amount' => '商品金额',
			'total' => '总计',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('productid',$this->productid,true);
		$criteria->compare('customerid',$this->customerid,true);
		$criteria->compare('cartid',$this->cartid,true);
		$criteria->compare('num',$this->num);
		$criteria->compare('amount',$this->amount);
		$criteria->compare('total',$this->total);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}